Skip to content

feat(go): eager scope creation + parameter-aware RHS inference#642

Merged
shivasurya merged 2 commits intomainfrom
shiva/pr-02-golang-thirdparty
Apr 7, 2026
Merged

feat(go): eager scope creation + parameter-aware RHS inference#642
shivasurya merged 2 commits intomainfrom
shiva/pr-02-golang-thirdparty

Conversation

@shivasurya
Copy link
Copy Markdown
Owner

Summary

  • Fix B.1 (eager scope creation): indexGoFunctions now accepts a GoTypeInferenceEngine and eagerly creates an empty GoFunctionScope for every indexed Go function during Pass 1. Eliminates [debug-1b] no scope for log messages for functions where all Pass 2b variable inferences fail.
  • Fix B.2 (param-aware RHS inference): New inferTypeFromParamMethodCall helper resolves method return types when the receiver matches a function parameter (e.g. r.FormValue("id")builtin.string via net/http.Request). Threads callGraph through ExtractGoVariableAssignments and its 5-function call chain.
  • Duplicates splitGoTypeFQN / resolveGoTypeFQN in the extraction package to avoid an import cycle with builder.

Test plan

  • TestIndexGoFunctions_EagerScopeCreation — scope exists for every indexed function
  • TestIndexGoFunctions_EagerScope_NilTypeEngine — no panic with nil engine
  • TestIndexGoFunctions_EagerScope_NotOverwritten — pre-existing Pass 2b bindings preserved
  • TestParamAwareRHSInference_StdlibParamr.FormValue("id")builtin.string via StdlibLoader
  • TestParamAwareRHSInference_ThirdPartyParamc.Query("search")builtin.string via ThirdPartyLoader
  • TestParamAwareRHSInference_NilCallGraph — graceful no-op with nil callGraph
  • TestParamAwareRHSInference_UnknownParam — no binding for non-parameter receiver
  • Full suite: go test ./... — 29/29 packages pass
  • Lint: golangci-lint run — 0 issues

🤖 Generated with Claude Code

@shivasurya shivasurya added enhancement New feature or request go Pull requests that update go code labels Apr 5, 2026
@shivasurya shivasurya self-assigned this Apr 5, 2026
@shivasurya shivasurya added enhancement New feature or request go Pull requests that update go code labels Apr 5, 2026
@safedep
Copy link
Copy Markdown

safedep bot commented Apr 5, 2026

SafeDep Report Summary

Green Malicious Packages Badge Green Vulnerable Packages Badge Green Risky License Badge

No dependency changes detected. Nothing to scan.

View complete scan results →

This report is generated by SafeDep Github App

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 5, 2026

Code Pathfinder Security Scan

Pass Critical High Medium Low Info

No security issues detected.

Metric Value
Files Scanned 7
Rules 205

Powered by Code Pathfinder

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 5, 2026

Codecov Report

❌ Patch coverage is 90.24390% with 8 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.22%. Comparing base (d610c54) to head (2c38068).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...-engine/graph/callgraph/extraction/go_variables.go 89.61% 4 Missing and 4 partials ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #642   +/-   ##
=======================================
  Coverage   84.21%   84.22%           
=======================================
  Files         162      162           
  Lines       23256    23327   +71     
=======================================
+ Hits        19586    19648   +62     
- Misses       2936     2940    +4     
- Partials      734      739    +5     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Owner Author

shivasurya commented Apr 7, 2026

Merge activity

  • Apr 7, 8:35 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Apr 7, 8:37 PM UTC: Graphite rebased this pull request as part of a merge.
  • Apr 7, 8:37 PM UTC: @shivasurya merged this pull request with Graphite.

@shivasurya shivasurya changed the base branch from shiva/pr-01-golang-thirdparty to graphite-base/642 April 7, 2026 20:35
@shivasurya shivasurya changed the base branch from graphite-base/642 to main April 7, 2026 20:35
shivasurya and others added 2 commits April 7, 2026 20:36
Fix B.1: indexGoFunctions now accepts a GoTypeInferenceEngine and creates
an empty GoFunctionScope for every indexed Go function during Pass 1.
This ensures Pattern 1b Source 2 always finds a scope even when all
variable inferences in Pass 2b fail (e.g., functions with only
parameter-based method calls).

Fix B.2: inferTypeFromRHS gains a parameter-aware fallback via the new
inferTypeFromParamMethodCall helper. When obj.Method() is encountered
and obj matches a function parameter, the method's return type is
resolved through StdlibLoader → ThirdPartyLoader (Check 2/2.5 order).
Thread callGraph through ExtractGoVariableAssignments and the 5
functions in its call chain to enable the param lookup.

Duplicates splitGoTypeFQN / resolveGoTypeFQN in the extraction package
to avoid an import cycle between extraction and builder.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add targeted tests for uncovered branches in inferTypeFromParamMethodCall:
- Package alias receiver (already handled by inferTypeFromFunctionCall)
- Method not found in type's method set
- Error-only return values (no usable non-error type)
- Unqualified parameter type (no dot → extractionSplitGoTypeFQN returns false)

Coverage for inferTypeFromParamMethodCall: 83.3% → 90.5%.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@shivasurya shivasurya force-pushed the shiva/pr-02-golang-thirdparty branch from 3b011a2 to 2c38068 Compare April 7, 2026 20:36
@shivasurya shivasurya merged commit 4eb8da7 into main Apr 7, 2026
6 checks passed
@shivasurya shivasurya deleted the shiva/pr-02-golang-thirdparty branch April 7, 2026 20:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant